package com.qianfeng.controller;

import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qianfeng.service.AsyncService;

@Controller
public class TestController {
  
	@Autowired
	private AsyncService asyncService;
	
	
	@RequestMapping("/show")
	@ResponseBody
	public String show() {
		//int a=5/0;
		int arr[]= new int[3];
		System.out.println(arr[51]);//下标越界异常
		return "hello world";
	}
	
	@RequestMapping("/async")
	@ResponseBody
	public String asyncTest() throws Exception {
		long start= System.currentTimeMillis();
		Future<String> task1=asyncService.doTask1();
		Future<String> task2=asyncService.doTask2();
		Future<String> task3=asyncService.doTask3();
		while(true) {
			if(task1.isDone()&&task2.isDone()&&task3.isDone()) {
				break;
			}
			Thread.sleep(1000);
		}
		long end= System.currentTimeMillis();
		return "全部结束，耗时"+(end-start)+"毫秒";
	}
	
	
}





















